package com.ruoyi.web.controller.danger;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.entity.LightningSensor;
import com.ruoyi.system.service.LightningSensorService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 雷电预警站点(LightningSensor)表控制层
 *
 * @author makejava
 * @since 2023-03-08 13:47:13
 */
@RestController
@RequestMapping("lightningSensor")
public class LightningSensorController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private LightningSensorService lightningSensorService;

    /**
     * 分页查询
     *
     * @param lightningSensor 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo queryByPage(LightningSensor lightningSensor) {
        startPage();
        List<LightningSensor> lightningSensors = this.lightningSensorService.queryByPage(lightningSensor);
        return getDataTable(lightningSensors);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<LightningSensor> queryById(@PathVariable("id") String id) {
        return ResponseEntity.ok(this.lightningSensorService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param lightningSensor 实体
     * @return 新增结果
     */
    @PostMapping("/create")
    public ResponseEntity<LightningSensor> add(LightningSensor lightningSensor) {
        return ResponseEntity.ok(this.lightningSensorService.insert(lightningSensor));
    }

    /**
     * 编辑数据
     *
     * @param lightningSensor 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<LightningSensor> edit(LightningSensor lightningSensor) {
        return ResponseEntity.ok(this.lightningSensorService.update(lightningSensor));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.lightningSensorService.deleteById(id));
    }

}

